import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum, UnitType} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";
import UnitUtil from "../../utils/UnitUtil";
import {DataRouter} from "../../frame/dataSource/DataRouter";
import {EffectModel} from "../../frame/apiModel/adapterModel/model2/EffectModel";
import {ModelFactory} from "../../frame/apiModel/adapterModel/model5/ModelFactory";
import {TimeControllerOpt} from "../../controller/model/ControllerOpt";
import {TimeController} from "../../controller/TimeController";
import MathUtil from "../../frame/codeAdapter/MathUtil";
import {GlobalEnv} from "../../utils/GlobalEnv";
import {ChangeUnitType} from "../../type/Type";
import {ConfigKey} from "../../constant/ConfigConstant";
import {ModelType} from "../../frame/apiModel/adapter/adapterInterface/model5/IModelFactory";

export default class EngulfPetSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.engulfPetSkill) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        this.engulfPetSkill(activeUnit, targetUnit)
        return success;
    }

    engulfPetSkill(activeUnit: UnitModel, targetUnit: UnitModel) {
        const player = PlayerFactory.getInstance().getUnitOwner(activeUnit);
        const hero = GlobalEnv.getHero(player);
        const isVaild = hero;
        if (isVaild) {
        } else {
            Logger.toastProduct('请选择人物后再操作宠物！', player);
            return;
        }
        const targetPlayer = PlayerFactory.getInstance().getUnitOwner(targetUnit);
        if (activeUnit === targetUnit) {
            Logger.toastProduct('不能吞噬自己!', player);
            return;
        }
        if (player === targetPlayer) {
        } else {
            Logger.toastProduct('只能吞噬自己的宠物', player);
            return;
        }
        const isPet = DataRouterUtil.checkIsPet(targetUnit);
        if (isPet) {
        } else {
            Logger.toastProduct('当前目标不能吞噬', player);
            return;
        }
        const subRadix: number = Configer.getConfig(ConfigKey.engulfPetSkillRadix);
        const currentExp = Util.getTargetAttributeEnumByNotHero(activeUnit, AttributeEnum.exp);
        const targetExp = Util.getTargetAttributeEnumByNotHero(targetUnit, AttributeEnum.exp);
        const newExp = currentExp + (targetExp * subRadix);
        Util.setTargetAttributeEnumToNotHero(activeUnit, AttributeEnum.exp, newExp);
        const index = UnitController.getInstance().getPetIndex(targetUnit, player);
        UnitController.getInstance().releasePet(player, index);
    }

}